//
// Created by steven on 2025/9/4.
//

#ifndef MAIN_IMAGE_CONVERTO_H
#define MAIN_IMAGE_CONVERTO_H

#include <vector>
#include <string>
#include <string>
#include "libavutil/frame.h"
#include "RivsInference/RivsInferRuntime.h"

struct AVFrame;
namespace rivscv {
    /**
 * @brief 目前输出数据的宽高尺寸是基于输入图片宽高与目标roi决定的，如果后续需要调整，请添加相应参数逻辑
 *
 * @param image
 * @param src_roi
 * @param dst_roi
 * @return AVFrame
 */

    struct RivsImageTensor
    {
        RivsImageTensor(int device_id = 0);
        RivsImageTensor(int device_id, const std::vector<int> &shape, const RivsInference::DataType data_type);
        RivsImageTensor(int device_id, void *data, const std::vector<int> &shape, const RivsInference::DataType data_type);
        virtual ~RivsImageTensor();

        void *m_data;
        size_t m_data_size;
        std::vector<int> m_shape;
        RivsInference::DataType m_data_type;
        bool m_own_data {false};
        int m_device_id;
    };

    struct Rect
    {
        Rect() : x(0), y(0), width(0), height(0) {}
        Rect(float x, float y, float width, float height):x(x), y(y), width(width), height(height){}
        float x, y;
        float width, height;
    };

    struct ConvertParam
    {
        ConvertParam()
        {
            m_swapRGB = false;
            m_scaleEnabled = false;
            m_scaleAlpha = 1.0;
        }

        bool m_swapRGB;
        bool m_scaleEnabled;
        float m_scaleAlpha;

        Rect m_srcROI;
        Rect m_dstROI;
    };


    int image_convert_to_L4(AVFrame *image, ConvertParam *param, RivsImageTensor *p_tensor);
    int image_convert_to_L3(AVFrame *image, ConvertParam *param, RivsImageTensor *p_tensor);
    void image_tensor_save(RivsImageTensor *p_tensor,const std::string& filepath);
    int image_convert_to_topcc(AVFrame *image, ConvertParam *param, RivsImageTensor *p_tensor);
    Rect image_keep_aspect_scale(const Rect& src, const Rect& dst);

}

#endif //MAIN_IMAGE_CONVERTO_H